import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_framework/views/home/ctrl/find_item_ctrl.dart';
import 'package:flutter_framework/views/home/models/find_item_model.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:get/instance_manager.dart';

class FindItem extends StatefulWidget {
  final FindItemModel itemData;
  const FindItem({super.key, required this.itemData});
  @override
  State<FindItem> createState() => _StatefulTemplateState();
}

class _StatefulTemplateState extends State<FindItem> {
  final FindItemCtrl _ctrl = Get.put(FindItemCtrl());
  @override
  void initState() {
    _ctrl.initData(widget.itemData);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<FindItemCtrl>(
      init: _ctrl,
      initState: (state) => {
        Timer(Duration.zero, () {
          state.controller?.initData(widget.itemData);
        })
      },
      id: '${widget.itemData.seqId}',
      builder: (ctrl) {
        return Container(
          width: 200,
          height: 200,
          margin: const EdgeInsets.only(top: 10),
          alignment: Alignment.center,
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(20), color: Colors.black38),
          child: Text(
            '${ctrl.itemData.nickName} ${ctrl.itemData.toJson()}',
            style: const TextStyle(color: Colors.white),
          ),
        );
      },
    );
  }
}
